/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package atm.charts;

import atm.connection.Connect;

import com.alee.laf.panel.WebPanel;

import java.util.ArrayList;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.CategoryAxis;
import org.jfree.chart.axis.CategoryLabelPositions;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.category.CategoryDataset;
import org.jfree.data.general.DatasetUtilities;

/**
 *
 * @author Quark
 */
public class AreaChartPanel extends WebPanel {

    private Connect connection;
    private ArrayList<Integer> w10;
    private ArrayList<Integer> w20;
    private ArrayList<Integer> w50;
    private ArrayList<Integer> w100;
    double[][] data;

    public void completeDataset(int i) {
        connection = new Connect();
        connection.getConnected();
        w10 = connection.getCashAmount10(1);
        w20 = connection.getCashAmount20(1);
        w50 = connection.getCashAmount50(1);
        w100 = connection.getCashAmount100(1);
        data = new double[][]{
            // [M, T, W, T, F, S, S]
            {(double) w10.get(0), (double) w10.get(1), (double) w10.get(2), (double) w10.get(3), (double) w10.get(4), (double) w10.get(5), (double) w10.get(6)}, // 10s
            {(double) w20.get(0), (double) w20.get(1), (double) w20.get(2), (double) w20.get(3), (double) w20.get(4), (double) w20.get(5), (double) w20.get(6)}, // 20s
            {(double) w50.get(0), (double) w50.get(1), (double) w50.get(2), (double) w50.get(3), (double) w50.get(4), (double) w50.get(5), (double) w50.get(6)}, // 50s
            {(double) w100.get(0), (double) w100.get(1), (double) w100.get(2), (double) w100.get(3), (double) w100.get(4), (double) w100.get(5), (double) w100.get(6)} // 100s
        };
    }

    public AreaChartPanel(int i) {
        completeDataset(i);
        CategoryDataset dataset = DatasetUtilities.createCategoryDataset("Series ", "D", data);

        ChartPanel chartPanel = new ChartPanel(createChart(dataset), false);
        chartPanel.setOpaque(false);

        this.add(chartPanel);
    }

    private JFreeChart createChart(final CategoryDataset dataset) {
        // chart title, domain axis label, range axis label, data, orientation, include legend, tooltips, urls
        final JFreeChart chart = ChartFactory.createAreaChart(null, null, null, dataset, PlotOrientation.VERTICAL, false, false, false);
        chart.setBackgroundPaint(null);

        final CategoryPlot plot = chart.getCategoryPlot();
        plot.setForegroundAlpha(0.7f);
        plot.setBackgroundPaint(null);
        plot.setOutlineVisible(false);
        plot.setDomainGridlinesVisible(false);
        plot.setRangeGridlinesVisible(false);

        final CategoryAxis domainAxis = plot.getDomainAxis();
        domainAxis.setCategoryLabelPositions(CategoryLabelPositions.STANDARD);
        domainAxis.setLowerMargin(0.0);
        domainAxis.setUpperMargin(0.0);

        final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
        rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
        rangeAxis.setLabelAngle(0 * Math.PI / 2.0);

        return chart;
    }
}
